package com.twu.biblioteca.view.console.resolver;

import com.twu.biblioteca.entity.User;
import com.twu.biblioteca.enums.MapKey;
import com.twu.biblioteca.view.console.ViewResolver;

import java.util.Map;

public class UserInfoViewResolver implements ViewResolver {
  public static final String HEADER =
      "-------------------------------------------\n"
          + "|             User Information            |\n"
          + "-------------------------------------------\n";

  public static final String END_LIE =
      "-------------------------------------------\n";

  private static final String BODY =
      "  Library Number: %s\n"
          + "  Name:           %s\n"
          + "  Email:          %s\n"
          + "  Address:        %s\n"
          + "  Phone:          %s\n";

  @Override
  public String getView(Map<MapKey, Object> model) {
    User user = (User) model.get(MapKey.User);
    return HEADER + getBody(user) + END_LIE;
  }

  private String getBody(User user) {
    return String.format(BODY, user.getLibraryNumber(),
        user.getName(),
        user.getEmail(),
        user.getAddress(),
        user.getPhoneNumber());
  }
}
